import { pubRequire, pubRequireFree } from '@utils/public'
import { Message } from 'element-ui'

/*获取预设用户列表*/
export function getUserRul(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}/preestablish-crowds`
    pubRequire(
      'get',
      url,
      '',
      (response) => {
        resolve(response.rows)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}

/*获取预设用户列表*/
export function getTouchSetting(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}/reachs`
    pubRequire(
      'get',
      url,
      '',
      (response) => {
        resolve(response.rows)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}
/*获取发放列表*/
export function getAllocatedMange(
  aggregationId,
  id,
  params,
  callbBack,
  errBack
) {
  return pubRequire(
    'get',
    `/prizes/${aggregationId}?activityId=${id}`,
    params,
    callbBack,
    errBack
  )
}
/*获取奖项状态*/
export function getAwardAll(obj, callbBack, errBack) {
  return pubRequire('get', `/activities/prize/options`, obj, callbBack, errBack)
}
/*修改发奖状态*/
export function batchAwardAll(obj, callbBack, errBack) {
  return pubRequire('put', `/prizes`, obj, callbBack, errBack)
}
/*修改发奖物流信息*/
export function awardlogistics(obj, callbBack, errBack) {
  return pubRequire('put', `/prizes/logistics`, obj, callbBack, errBack)
}
//导入接口
export function importUrl() {
  return `/prizes/import
  `
}
//下载模板接口
export function downUrl() {
  return `/prizes/download`
}

/*获取预设用户列表*/
export function getSubFormData(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}`
    pubRequire(
      'get',
      url,
      '',
      (response) => {
        resolve(response)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}

/*删除活动*/
export function delActive(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}`
    pubRequire(
      'delete',
      url,
      '',
      (response) => {
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}

/*活动下线*/
export function offline(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}/disable`
    pubRequire(
      'put',
      url,
      '',
      (response) => {
        Message.success('操作成功')
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}

/*提交*/
export function submitActive(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}/submit`
    pubRequire(
      'put',
      url,
      '',
      (response) => {
        Message.success('提交成功')
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}

/*获取活动id*/
export function getId(activeType) {
  return new Promise((resolve, reject) => {
    let url = '/activities'
    let obj = {
      classify: '', //活动类型对应中文
      type: activeType, //活动类型 OFFICIAL_SELF_JUDGE_ACTIVITY：官方自评活动；QUESTIONNAIRE_ACTIVITY：调查问卷活动；VOTE_ACTIVITY：投票活动;BELOW_THE_LINE_ACTIVITY：线下汇报活动;RANKING_LIST_ACTIVITY：排行榜活动
      name: '', // 活动名称
      describe: '', // 活动描述
      remark: '', // 备注
      source: 'OTHER' //活动来源OTHER写死
    }
    delete obj.classify
    pubRequireFree(
      'post',
      url,
      obj,
      (response) => {
        resolve(response.data)
      },
      (res) => {
        Message.warning(response.message)
        reject(res)
      }
    )
  })
}

/*删除预设用户*/
export function delReach(id, pid) {
  return new Promise((resolve, reject) => {
    let url = `/activities/${id}/preestablish-crowds/${pid}`
    pubRequire(
      'delete',
      url,
      '',
      (response) => {
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}
/*查询奖品配置信息*/
export function getPrize(id) {
  return new Promise((resolve, reject) => {
    let url = `/activities/prize`
    let obj = {
      relevanceId: id,
      relevanceType: 'ACTIVITY'
    }
    pubRequire(
      'get',
      url,
      obj,
      (response) => {
        resolve(response)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}

// 延长服务期列表
export function extensionServer(obj, callbBack, errBack) {
  return pubRequire('get', `/orders/extended-services/users`, obj, callbBack, errBack)
}
// 下载发放模板

export function DownloadingTemplate(obj, callBack, errBack) {
   return `/orders/extended-services/users/download`
}
// 订单确认
export function confirmOrder(id,obj, callbBack, errBack) {
  return pubRequire('put', `/orders/extended-services/users/confirm/${id}`, obj, callbBack, errBack)
}
// 删除
export function deleteOrder(id,obj, callBack, errBack) {
  return pubRequire('delete', `/orders/extended-services/users/${id}`, obj, callBack, errBack)
}
// 用户导入
export function importUserUrl(activityId) {
  return `/orders/extended-services/users/${activityId}/import`
}

// 批量订单确认

export function batchOrder(obj, callBack, errBack) {
  return pubRequire('put', `/orders/extended-services/users/confirm`, obj, callBack, errBack)
}